package com.ruoyi.web.controller.system.api.cc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.ServiceNotice;
import com.ruoyi.system.api.domain.ServiceNoticeCount;
import com.ruoyi.system.api.service.IServiceNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * @author tiejun.zhang
 * @program:
 * @description:
 * @date 2020-07-04 14:37
 */
@Api(tags = "服务通知计数")
@Controller
@RequestMapping("/api/cc/noticeCount")
public class ServiceNoticeCountController {

    @Autowired
    private IServiceNoticeService serviceNoticeService;


    @GetMapping()
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "通知计数的查询", httpMethod = "GET", notes = "通知计数的查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师主键ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query")})
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功", response = ServiceNotice.class)
    })
    public ResponseWithData getServiceNoticeCount(@RequestParam(value = "enginnerId") String enginnerId){
        ServiceNoticeCount serviceNoticeCount = new ServiceNoticeCount();
        //待指派服务数量
        ServiceNotice serviceNotice2 = new ServiceNotice();
        serviceNotice2.setTeamleaderId(enginnerId);
        serviceNotice2.setProvince("1");
        int ll = serviceNoticeService.getTeamServiceNoticesCount(serviceNotice2);
        serviceNoticeCount.setTobeAssignedCount(ll);
        //待接受服务数量
        serviceNoticeCount.setTobeAcceptedCount(serviceNoticeService.getServiceNoticeListCount(enginnerId, "0"));
        //已接受服务数量
        serviceNoticeCount.setAcceptedCount(serviceNoticeService.getServiceNoticeListCount(enginnerId, "1"));
        //已签到服务数量
        serviceNoticeCount.setSignInCount(serviceNoticeService.getServiceNoticeListCount(enginnerId, "2"));
        //已签离服务数量
        serviceNoticeCount.setSignOffCount(serviceNoticeService.getServiceNoticeListCount(enginnerId, "3"));
        //自动签离服务数量
        serviceNoticeCount.setAutoSignOffCount(serviceNoticeService.getServiceNoticeListCount(enginnerId, "5"));
        //已完成服务数量
        serviceNoticeCount.setCompletedCount(serviceNoticeService.getServiceNoticeListCount(enginnerId, "4"));

        ServiceNotice serviceNotice = new ServiceNotice();
        serviceNotice.setTeamleaderId(enginnerId);
        serviceNotice.setServiceLevel("1,2");
        //团队服务通知数量
        serviceNoticeCount.setTeamServiceNoticeCount(serviceNoticeService.getTeamServiceNoticesBytl(serviceNotice).size());
        //未关闭服务数量
        serviceNotice.setTeamleaderId(null);
        serviceNotice.setEnginnerId(Long.parseLong(enginnerId));
        serviceNoticeCount.setUnfinishedCount(serviceNoticeService.getTeamServiceNoticeCount(serviceNotice));
        return new ResponseWithData<>().success(serviceNoticeCount).msg("查询成功").code(200);
    }
}
